﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace COFE.Core.UnitTest
{
    public interface ITestUserCreator
    {        
        /// <summary>
        /// Create
        /// </summary>
        /// <param name="name"></param>
        /// <param name="registerVolume">FactoryKey, ListerKey and Param</param>
        /// <returns></returns>
        IUserProfile CreateUser(string name, params Tuple<string, string, string>[] registerVolume);
    }

    public static class ITestUserCreatorExtension
    {

        /// <summary>
        /// Create a user with a default volume TEMP linked to a newly created temp directory. (also register SevenZipDirectoryLister).
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static IUserProfile CreateUser(this ITestUserCreator tuc, string name, 
            ITempDirectoryConstructor tempCreator, 
            out DirectoryInfo tempDir, params Tuple<string, string, string>[] registerExtraVolume)
        {
            tempDir = tempCreator.ConstructDirectory();

            List<Tuple<string, string, string>> registerVolume = 
                new List<Tuple<string, string, string>>(registerExtraVolume);
            registerVolume.Insert(0, new Tuple<string, string, string>("FSI", "TEMP", "path="+ tempDir.FullName));
            registerVolume.Insert(1, new Tuple<string, string, string>("SZ", "SZ", ""));

            var user = tuc.CreateUser(name, registerVolume.ToArray());
            return user;
        }
    }
}
